package LeetCode;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName interview
 * @Description: TODO
 * @date ${DAT}15:18
 */
public class LeetCode404 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) { val = x; }
    }
    public int sumOfLeftLeaves(TreeNode root) {
        return sumOfLeftLeaves(root,false);
    }

    private int sumOfLeftLeaves(TreeNode root, boolean flag) {
        if (root == null){
            return 0;
        }

        if (root.left == null && root.right == null && flag){ // 这里是左右子节点
            return root.val;
        }

        int left = sumOfLeftLeaves(root.left,true);
        int right = sumOfLeftLeaves(root.right,false);

        return left + right;
    }
}
